package com.yrw.zcy.sort;

/**
 * @ClassName SelectionSort
 * @Author 12694
 * @Date 2024/11/3 19:52
 * @Version 1.0
 **/
public class SelectionSort {
    public static void main(String[] args) {
        int[] arr = {1, 3, 2, 5, 4, 6, 7, 8, 9, 0};
        selectionSort(arr);
        for (int i : arr) {
            System.out.print(i + " ");
        }
    }
    public static void selectionSort(int[] arr){
        for (int minIndex,i=0;i<arr.length-1;i++){
            minIndex = i;
            for (int j=i+1;j<arr.length;j++){
                if (arr[j]<arr[minIndex]){
                    minIndex = j;
                }
            }
            swap(arr, minIndex, i);
        }
    }
    public static void swap(int[] arr,int a, int b){
        int temp = arr[a];
        arr[a] = arr[b];
        arr[b] = temp;
    }
}
